import {
    GETDATA,
    F,
    G
} from '../utils/R'
export default {
    namespace: 'leftTop',
    state: {
        zyzs: undefined,
        kjzs: undefined
    },
    subscriptions: {
        setup({
            dispatch,
            history
        }) {
            history.listen(({
                pathname
            }) => {
                if (pathname == "/two") {
                    dispatch({
                        type: 'getData'
                    })
                }
            })
        }
    },
    effects: {
        * getData({
            paylaod
        }, {
            call,
            put
        }) {
            let {
                data
            } = yield call(GETDATA, F) //测试资源 zyzs
            if (data) {
                yield put({
                    type: 'setState',
                    payload: {
                        zyzs: data[0]
                    }
                })
            }
            let {
                data: d
            } = yield call(GETDATA, G) //课件总数 kjzs
            if (d) {
                yield put({
                    type: 'setState',
                    payload: {
                        kjzs: d[0]
                    }
                })
            }
        }
    },
    reducers: {
        setState(state, action) {
            return {
                ...state,
                ...action.payload
            }
        }
    }
}